/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class SolutionDAO {
	public static Solution loadSolutionByORMID(int idSolution) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadSolutionByORMID(session, idSolution);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution getSolutionByORMID(int idSolution) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return getSolutionByORMID(session, idSolution);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution loadSolutionByORMID(int idSolution, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadSolutionByORMID(session, idSolution, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution getSolutionByORMID(int idSolution, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return getSolutionByORMID(session, idSolution, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution loadSolutionByORMID(PersistentSession session, int idSolution) throws PersistentException {
		try {
			return (Solution) session.load(orm.Solution.class, new Integer(idSolution));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution getSolutionByORMID(PersistentSession session, int idSolution) throws PersistentException {
		try {
			return (Solution) session.get(orm.Solution.class, new Integer(idSolution));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution loadSolutionByORMID(PersistentSession session, int idSolution, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Solution) session.load(orm.Solution.class, new Integer(idSolution), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution getSolutionByORMID(PersistentSession session, int idSolution, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Solution) session.get(orm.Solution.class, new Integer(idSolution), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution[] listSolutionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return listSolutionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution[] listSolutionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return listSolutionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution[] listSolutionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Solution as Solution");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Solution[]) list.toArray(new Solution[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution[] listSolutionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Solution as Solution");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Solution[]) list.toArray(new Solution[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution loadSolutionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadSolutionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution loadSolutionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadSolutionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution loadSolutionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Solution[] solutions = listSolutionByQuery(session, condition, orderBy);
		if (solutions != null && solutions.length > 0)
			return solutions[0];
		else
			return null;
	}
	
	public static Solution loadSolutionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Solution[] solutions = listSolutionByQuery(session, condition, orderBy, lockMode);
		if (solutions != null && solutions.length > 0)
			return solutions[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateSolutionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return iterateSolutionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateSolutionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return iterateSolutionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateSolutionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Solution as Solution");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateSolutionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Solution as Solution");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution createSolution() {
		return new orm.Solution();
	}
	
	public static boolean save(orm.Solution solution) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().saveObject(solution);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(orm.Solution solution) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().deleteObject(solution);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.Solution solution)throws PersistentException {
		try {
			if(solution.getDiagnoseidDiag() != null) {
				solution.getDiagnoseidDiag().setSolution(null);
			}
			
			return delete(solution);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.Solution solution, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(solution.getDiagnoseidDiag() != null) {
				solution.getDiagnoseidDiag().setSolution(null);
			}
			
			try {
				session.delete(solution);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(orm.Solution solution) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().getSession().refresh(solution);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(orm.Solution solution) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().getSession().evict(solution);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Solution loadSolutionByCriteria(SolutionCriteria solutionCriteria) {
		Solution[] solutions = listSolutionByCriteria(solutionCriteria);
		if(solutions == null || solutions.length == 0) {
			return null;
		}
		return solutions[0];
	}
	
	public static Solution[] listSolutionByCriteria(SolutionCriteria solutionCriteria) {
		return solutionCriteria.listSolution();
	}
}
